package com.ancient.web.data1.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ancient.base.page.Page;
import com.ancient.base.page.ResponseResult;
import com.ancient.web.data1.dao.UserDao;
import com.ancient.web.data1.entity.User;
import com.ancient.web.data1.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class UserServiceImpl implements UserService{
	@Resource
	private UserDao userdao;
	
	@Override
	public List<User> getUsers(User user) {
		log.debug("===");
		return userdao.getUsers(user);
	}
	
	@Override
//	@Transactional
	public void addUser(User user){
		userdao.addUser(user);
		System.out.println(1/0);
	}
	
	@Override
	@Transactional
	public void delUserById(int id) {
		userdao.delUserById(id);
	}

	@Override
	public ResponseResult<List<User>> userList(User record) {
		PageHelper.startPage(record.getDisplayStart(), record.getDisplayLength());
		List<User> list = userdao.getUsers(record);
		PageInfo<User > pageInfo = new PageInfo<>(list);
		Page page = new Page();
		if (pageInfo.getList() != null && pageInfo.getList().size() > 0) {
			page = new Page(pageInfo);
		}
		return new ResponseResult<>(list, page);
	}

}
